package com.ny.dao.impl;
import com.ny.dao.OrderDao;
import com.ny.entity.Order;
import com.ny.until.SqlConnection;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class OrderDaoImpl implements OrderDao {

    private SqlConnection  sqlConnection = new SqlConnection();

    public OrderDaoImpl() throws ClassNotFoundException, SQLException {
    sqlConnection.getCon();
    }

    @Override
    public int addOrder(Order order) throws SQLException, ClassNotFoundException {

        String  sql = "insert into orders(student_id,product_id,number,total_price) values(?,?,?,?)";

        PreparedStatement  preparedStatement = sqlConnection.getCon().prepareStatement(sql);
        preparedStatement.setInt(1,order.getStudent_id());
        preparedStatement.setInt(2,order.getProduct_id());
        preparedStatement.setInt(3,order.getNumber());
        preparedStatement.setDouble(4,order.getTotal_price());
        return preparedStatement.executeUpdate();
    }
}
